package secondStage.part4.特殊操作流.猜数字;

import java.util.Random;
import java.util.Scanner;

/**
 * @ClassName: [GuessNumber]
 * @Description: 猜数字游戏类
 * @Author: [黄劲松]
 * @CreateDate: [2021-04-05]
 * @Version: [v1.0]
 */
public class GuessNumber {
    private GuessNumber(){
    }
    public static void start(){
        //产生随机数
        Random r = new Random();
        int number = r.nextInt(100)+1;

        while (true){
            //使用程序是实现猜数字，每次要输入猜测的数字，使用键盘录入
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入你要猜的数字：");
            int guessNumber = sc.nextInt();
            //比较输入的数字和系统随机产生的数据
            if (guessNumber>number){
                System.out.println("你猜的数字大了！");
            }else if (guessNumber<number){
                System.out.println("你猜的数字小了");
            }else{
                System.out.println("恭喜你猜中了");
                break;
            }
        }
    }
}
